package eu.codlab.androidemu.utilities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Build;

public class ReportHelper {
	public static void sendReport(Context context, int type, Class<? extends Activity> class_sender, String file, int error){
		String emailList[] = {"pokeke100@gmail.com"};
		Intent intent = new Intent(Intent.ACTION_SEND);  
		intent.setType("plain/text");
		intent.putExtra(Intent.EXTRA_EMAIL, emailList);   
		if(type == 0)
			intent.putExtra(Intent.EXTRA_SUBJECT, "[GBA ERROR] load Error bios");
		else if(type == 1)
			intent.putExtra(Intent.EXTRA_SUBJECT, "[GBA ERROR] load Error rom load");
		else if(type == 2)
			intent.putExtra(Intent.EXTRA_SUBJECT, "[GBA ERROR] load Error no bios");
		else
			intent.putExtra(Intent.EXTRA_SUBJECT, "[GBA ERROR] load Error type unknown");

		String txt="File loaded : "+file+" from "+class_sender.getName()+"\n";
		txt+="Code erreur : "+error+"\n";
		txt+="Android version : "+Build.VERSION.RELEASE+" running on "+Build.MODEL+"\n";
		int version = 0;
		try{
			PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); 
			version = packageInfo != null ? packageInfo.versionCode : 0; 
		}catch(Exception e){
			version = 0;
		}
		txt+="APK int : "+version+"\n";
		txt+="SDK int : "+Build.VERSION.SDK_INT+"\n";
		txt+="SDK Code : "+Build.VERSION.SDK+"\n";
		intent.putExtra(Intent.EXTRA_TEXT, txt);
		context.startActivity(Intent.createChooser(intent, "Send the bios/game error!"));
		
	}
}
